using UnityEngine;

/// <summary>
/// 障碍物控制器：控制单个障碍物的行为
/// </summary>
public class ObstacleController : MonoBehaviour
{
    [Header("移动设置")]
    [Tooltip("移动速度")]
    [SerializeField] private float moveSpeed = 10f;
    [Tooltip("左边界位置")]
    [SerializeField] private float leftBound = -15f;

    private PlayerController playerController;

    void Start()
    {
        // 获取玩家控制器引用
        playerController = GameObject.Find("Player").GetComponent<PlayerController>();
    }

    void Update()
    {
        // 如果游戏结束，停止移动
        if (playerController != null && playerController.IsGameOver())
        {
            return;
        }

        // 向左移动
        transform.Translate(Vector3.left * Time.deltaTime * moveSpeed);

        // 检查是否超出边界
        if (transform.position.x < leftBound)
        {
            Destroy(gameObject);
        }
    }
} 